package com.com.effectivejava.generics.examples.typemethod;

import java.util.Collection;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.logging.Logger;

/**
 * Created by User on 25/07/2014.
 */
public class Example {
    static Logger logger = Logger.getLogger(Example.class.getName());

    static {
        logger.setParent(Logger.getLogger(Example.class.getPackage().getName()));
    }

    public static void main (String[ ] args) {
        LinkedList<Byte> byteList = new LinkedList<Byte>();
        byteList.add(new Byte((byte)0));
        byteList.add(new Byte((byte)1));
        Byte y = Collections.max(byteList);
        logger.info(""+y.byteValue());

        LinkedList<Integer> intList = new LinkedList<Integer>();
        intList.add(new Integer(0));
        intList.add(new Integer(4));
        intList.add(new Integer(-1));

        Integer i = Collections.max(intList);
        logger.info(""+ i.intValue());
    }

}

interface Comparable<A> {
    public int compareTo (A that);
}

final class Byte implements Comparable<Byte> {
    private byte value;
    public Byte (byte value) { this.value = value; }
    public byte byteValue () { return value; }
    public int compareTo (Byte that) {
        return this.value - that.value;
    }
}

final class Integer implements Comparable<Integer>{
    private int value;
    public Integer(int value){
        this.value = value;
    }
    public int intValue(){
        return value;
    }
    public int compareTo(Integer that){
        return this.value - that.value;
    }
}

class Collections {
    public static < A extends Comparable<A> > A max (Collection<A> xs) {
        Iterator<A> xi = xs.iterator();
        A w = xi.next();
        while (xi.hasNext()) {
            A x = xi.next();
            if (w.compareTo(x) < 0) w = x;
        }
        return w;
    }
}

final class Test {

}
